package com.csdj.controller;

import com.csdj.common.WebResult;
import com.csdj.entity.driverSchool;
import com.csdj.service.driverSchoolService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/app")
public class driverSchoolController {
    @Resource
    driverSchoolService schoolService;
        @GetMapping("list")
            public String list(){

            return "schoolList";
            }

/*        @ResponseBody
    @GetMapping("sc")
    public List<driverSchool> scholl( Model model){
        List<driverSchool> list=schoolService.getallschool();

        return list;
    }*/

@GetMapping("school")
    public String sholl(@RequestParam(required=true,defaultValue="1") Integer page, Model model){
        PageHelper.startPage(page,2);
        List<driverSchool> list=schoolService.getallschool();
        PageInfo<driverSchool> p=new PageInfo<>(list);
          model.addAttribute("gamelist",list);
        model.addAttribute("p",p);

                return "schoolList";
    }



    @ResponseBody
    @GetMapping("updateDs")
    public String updateDs(driverSchool driverSchool,
                           @RequestParam(value = "name",required = false) String name,
                           @RequestParam(value = "cityAreaId",required = false) Integer cityAreaId,
                           @RequestParam(value = "address",required = false) String address,
                           @RequestParam(value = "phone",required = false) String phone){
        driverSchool.setName(name);
        driverSchool.setCityAreaid(cityAreaId);
        driverSchool.setAddress(address);
        driverSchool.setPhone(phone);
        Integer result = schoolService.updateDs(driverSchool);
        if(result>0){
            return "true";
        }else {
            return "false";
        }
    }

    @ResponseBody
    @GetMapping("selDsId")
    public WebResult selDsId(@RequestParam(value = "id",required = true) Integer id){
        driverSchool driverSchool = schoolService.selDsId(id);
        WebResult webResult = new WebResult();
        webResult.putData("driverSchool",driverSchool);
        return webResult;
    }

}